﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using UnwiseSource.ServiceReference1;

namespace UnwiseSource
{
    public partial class Site : System.Web.UI.MasterPage
    {
        private const string salt = "MARTOIBORKOSAPICHOVE";
        private Service1Client unwiseSourceService = new Service1Client();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Random random = new Random();
                int quoteNumber = random.Next(1, 100);
                string accessKey = Helper.getconfigparam("SECID", "");
                Quotes newQuote = new Quotes();
                try
                {
                    newQuote = unwiseSourceService.ReadAQuote(accessKey, quoteNumber);
                }
                catch (Exception ex)
                {
                    Helper.LogErrorMsg(ex.ToString());
                }
                quote.InnerText = newQuote.Quote;
                author.InnerText = newQuote.Author;
            }
        }

        protected void timer_Tick(object sender, EventArgs e)
        {
            Random random = new Random();
            int quoteNumber = random.Next(1, 100);
            string accessKey = Helper.getconfigparam("SECID", "");
            Quotes newQuote = new Quotes();
            try
            {
                newQuote = unwiseSourceService.ReadAQuote(accessKey, quoteNumber);
            }
            catch (Exception ex)
            {
                Helper.LogErrorMsg(ex.ToString());
            }
            quote.InnerText = newQuote.Quote;
            author.InnerText = newQuote.Author;
        }
    }
}